package com.ln.prac.base.xiaoao.collections;

import java.util.NavigableSet;
import java.util.TreeSet;

/**
 * {@link NavigableSet}Demo， 可以预览的
 *
 * @Author zhangj
 * @Date 2023/1/27 18:36
 */
public class NavigableSetDemo {

    public static void main(String[] args) {
        Integer x = 3;
        TreeSet<Integer> treeSet = new TreeSet() {
            {
                add(x);
                add(3);
                add(7);
                add(2);
                add(81);
            }
        };

        // 获取前继节点
        Integer lower = treeSet.lower(x);
        // 获取后继节点
        Integer higher = treeSet.higher(x);

        System.out.printf("lower: %d \n", lower);
        System.out.printf("higher: %d \n", higher);

        // 获取前继节点，含有等于的情况
        Integer floor = treeSet.floor(x);
        // 获取后继节点，含有等于的情况
        Integer ceiling = treeSet.ceiling(x);

        System.out.printf("floor: %d \n", floor);
        System.out.printf("ceiling: %d \n", ceiling);
    }

}
